<template>
  <view class="login">
	
    <view class="login-tel">
      <view class="tel-main">
		  <view class="logo">
	  	<image src="../../static/logoall3.png" alt="">
		  </view>
		<view class="page container">
			<uni-card :is-shadow="false" is-full>
		
			</uni-card>
			<uni-section :title="'日期用法：' + dateString" type="line"></uni-section>
			<view class="example-body">
				<uni-datetime-picker type="date" :clear-icon="false" v-model="dateString" @maskClick="maskClick" @change="saveSelectedDate" />
			</view>
				<view v-if="!this.databb" class="tip">请选择生日</view>
			<view class="example-body">
				<text>已保存的日期值：{{ databb }}</text>
			</view>
		<uni-button class="tel" @click="gonextcode">保存</uni-button> <!-- 新增提交按钮 -->
		</view>
      </view>
  
    </view>
  </view>
    </view>
  
</template>

<script>
	import {mapMutations} from 'vuex';
	import $http from '@/common/api/request.js'//引入request组件


export default {
  data() {
    return {
		databb:'',
		dateString: this.getDateTime(new Date()),
		datetimeString: this.getDateTime(new Date(), false),
		datetimeDefaultValueString: '',
		datetimeDefaultValue: this.getDateTime(Date.now() + 1 * 24 * 3600000),
		dateTimestamp: Date.now(),
		dateInstance: new Date(),
		dateRange: [this.getDate(Date.now() - 5 * 24 * 3600000), this.getDate(Date.now() + 5 * 24 * 3600000)],
		datetimeRange: [this.getDateTime(Date.now() - 5 * 24 * 3600000), this.getDateTime(Date.now() + 5 * 24 * 3600000)],
		start: Date.now() - 10 * 24 * 3600000,
		end: Date.now() + 10 * 24 * 3600000,
     birth: '',
	  userId:'',
	  phone:'',
	  user:[],
	users:[],
      showTip: false,
    
    }
  },
  mounted() {

  	this.gonextcode();
  	//全局变量用户ID
  //	this.userId = uni.getStorageSync('userId');
  		this.user = uni.getStorageSync('user');
  		//this.userName = uni.getStorageSync('user.name');
  		console.log('5551',this.user.id)
  	//this.address();
  },
  watch: {
  	datetimeString() {
  		console.log('日期时间单选:', this.datetimeString);
  	},
  	dateRange() {
  		console.log('日期范围选:', this.dateRange);
  	},
  	datetimeRange() {
  		console.log('日期时间范围选:', this.datetimeRange);
  	}
  },
  methods: {
  goToBack() {
  	uni.navigateTo({
  		url: '/pages/set/set'
  	})
  },
	change(e) {
				console.log('----change事件:', e);
			},
			maskClick() {
				console.log('----maskClick事件');
			},
			getDateTime(date, addZero = true){
				return `${this.getDate(date, addZero)} ${this.getTime(date, addZero)}`
			},
			getDate(date, addZero = true){
				date = new Date(date)
				const year = date.getFullYear()
				const month = date.getMonth()+1
				const day = date.getDate()
				return `${year}-${addZero ? this.addZero(month) : month}-${addZero ? this.addZero(day) : day}`
			},
			getTime(date, addZero = true){
				date = new Date(date)
				const hour = date.getHours()
				const minute = date.getMinutes()
				const second = date.getSeconds()
				return this.hideSecond ?
				`${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}` :
				`${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}:${addZero ? this.addZero(second) : second}`
			},
			addZero(num) {
				if (num < 10) {
					num = `0${num}`
				}
				return num
			},
			saveSelectedDate() {
				this.databb = this.dateString; // 将选中的日期值保存到databb变量中
				console.log('选中的日期值11:', this.dateString);
			},
      submit() {
        console.log('保存的日期值1:', this.databb); // 在提交按钮点击时打印保存的日期值
      },

/////////////////////////////////////////////////////////////////////////
  
///
	
gonextcode() {
	  console.log('保存的日期值123:', this.databb); // 在提交按钮点击时打印保存的日期值
	
  if (!this.databb) {
    this.showTip = true; // 显示提示信息
  } else {
    this.showTip = false; // 隐藏提示信息


 var birth = this.databb;
  console.log('997',this.user.Name)
  var userId = this.user.id;
  console.log('669', this.user.id)

  var url = 'http://43.136.172.73/api/v1/user/upgrade_birth';
  var id=this.user.id;
  url += '?birth=' + encodeURIComponent(birth) + '&userId=' + encodeURIComponent(userId);

  uni.request({
    url: url,
    method: 'PUT',
    header: {
      'Content-Type': 'application/json',
      "Content-Type": "application/x-www-form-urlencoded",
      'Authorization': 'sfsdf',
    },
    success: (res)=> {
      // 请求成功处理
      console.log('请求成功！',res);
	uni.request({
	  url: 'http://43.136.172.73/api/v1/user/load',
	  method: 'GET',
	  data: { 
	  	phone: this.user.phone, //给后端给的phone
	  },
	  header: {
	    'Content-Type': 'application/json',
	    'Content-Type': 'application/x-www-form-urlencoded',
	    'Authorization': 'sfsdf'
	  },
	  success: (res) => {
		  	console.log('5555:', this.user.phone)
	console.log('99966:', res.data)
	this.users = res.data.data;
	 console.log('6666:', this.users.birth)
   uni.showToast({
		          title: '修改成功',
		          icon: 'none',
		          duration: 2000
		        });
	setTimeout(() => {
				  uni.navigateTo({
				    url: '../set/set?birth=' + this.users.name
				  });
				}, 2000);
	
	  },
	  fail: (err) => {
	    console.error('Error:', err)
	  }
	})
    },
    fail: (err)=> {
      // 请求失败处理
      console.log('请求失败！', err);
    }
  });
  }
/////////////////////////////////////////////////////////////////////////
  
///加载

		
    }
	
  }
}
</script>

<style>
	
	.content-title {
		background-color: #fff;
		color: #000;
		font-weight: bold;
		height: 100rpx;
		position: relative;
		font-size: 16px;
	
		.title-left {
			position: absolute;
			left: 30rpx;
			top: 50%;
			transform: translate(-50%, -50%);
		}
	
		.title-right {
			text-align: center;
			line-height: 100rpx;
		}
	}
	
.login-tel {
  padding: 30rpx;
  width: 100vw;
  height: 100vh;
}

.tel-main {
  padding: 0rpx 20rpx;
  padding-top: 0rpx;
}
.logo{
	padding-top: 70rpx;
	padding-bottom: 80rpx;
	display: flex;
	justify-content: center;
	
}


.no-border {
outline: none;
  border:none ;
  background-color: #f7f7f7;
  display: flex;
  align-items: center;
  height: 50rpx;
  line-height: 50rpx;
  font-size: 28rpx; 
}

.btn {
  margin-left: -20rpx;
  margin-right: -20rpx;
  padding: 50rpx;
}
.tip{
	color: red;
}
	.example-body {
		background-color: #fff;
		padding: 10px;
	}
	.tel {
	  height: 100rpx;
	  line-height: 100rpx;
	  text-align: center;
	  color: #FFFF;
	  background-color: #49BDFB;
	  border-radius: 40rpx;
	}
</style>

